%Figure S4
clear variables

load('FigS4_weather_county.mat')

%% Figure S4 Panel A
%county level figures could take some time to render.

figure
ax = usamap('all');
set(ax(1), 'Visible', 'off')
set(ax(2), 'Visible', 'off')
set(ax(3), 'Visible', 'off')

names = {county_shape.state};
indexHawaii_c = strcmp('Hawaii',names);
indexAlaska_c = strcmp('Alaska',names);
indexConus_c = 1:numel(county_shape);
indexConus_c(indexHawaii_c|indexAlaska_c) = []; 

states = shaperead('usastatelo', 'UseGeoCoords', true);
names = {states.Name};
indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);
indexConus = 1:numel(states);
indexConus(indexHawaii|indexAlaska) = [];

surfaceColors = makesymbolspec('Polygon', ...
    {'r', [-1 1], 'FaceColor', flipud(cmap) });


% Display the three regions.
geoshow(ax(1), county_shape(indexConus_c),  'DisplayType','polygon','SymbolSpec', surfaceColors,...
    'DefaultFaceColor','#C0C0C0	','DefaultEdgeColor','none')
 geoshow(ax(2), county_shape(indexAlaska_c), 'DisplayType','polygon','SymbolSpec', surfaceColors,...
     'DefaultFaceColor','#C0C0C0	','DefaultEdgeColor','none')
geoshow(ax(3), county_shape(indexHawaii_c), 'DisplayType','polygon','SymbolSpec', surfaceColors,...
    'DefaultFaceColor','#C0C0C0	','DefaultEdgeColor','none')

%plot state lines
geoshow(ax(1), states(indexConus),'DisplayType','polygon','DefaultFaceColor','none')
 geoshow(ax(2), states(indexAlaska),'DisplayType','polygon','DefaultFaceColor','none')
geoshow(ax(3), states(indexHawaii),'DisplayType','polygon','DefaultFaceColor','none')

% Hide the frame.
caxis([-1 1])
colormap(flipud(cmap))
colorbar

for k = 1:3
        setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
          'ParallelLabel', 'off', 'MeridianLabel', 'off')
end

%% Figure S4 Panel B
figure
scatter(log10(table2array(county_unacast(1:end,5))),r_observed_county_e(:,1))
xlabel('Log of population density')
ylim([-0.7 0.7])
ylabel('Temperature-Encounters Correlation')